Release 10.1A: OpenEdge Development:
Progress 4GL Handbook


Block-related tips

This section offers some advice on creating blocks of code.

Using DO instead of REPEAT

Back in Chapter 6, "Procedure Blocks and Data Access," you learned about the various properties of different kinds of blocks. Remember that the DO block, by default, does not provide you with many of the default services that the REPEAT block does (for example, transaction management and default frame management). The flip side of this is that a DO block is much faster than a REPEAT block if you don’t need these services. So, use a simple DO block whenever possible for any kind of iterating block that doesn’t need to manage a transaction or iterate through a DOWN frame.

Minimizing block nesting

All blocks in Progress incur some overhead. Because Progress is a 4GL that provides many services to make programming easier and to make each statement do more than you’re used to from other languages, there is a cost to all blocks, even simple DO blocks. For this reason, you should avoiding unnecessary block nesting wherever possible. Therefore, always use the form:

 IF expression THEN statement. 

Instead of this form:

  IF expression THEN 
    DO: 
       statement. 
    END. 

The AppBuilder always gives you a DO END block as a starting point for triggers, for instance. You should feel free to remove the block if your trigger requires only a single statement. And remember that there can be an additional benefit to combining multiple assignments into a single statement. If you turn several assignments into a single ASSIGN statement, a DO block that would otherwise have several statements can be reduced to just one statement with no block header.

Minimizing nesting of procedure calls

Procedures, whether internal or external, are blocks as well, and relatively expensive ones. Obviously, you should use procedures as necessary to structure your application properly. However, if you run a relatively small procedure or invoke a function many times in a performance-sensitive loop, you should consider moving the code directly into the procedure that calls it to execute it inline. If it’s executed many times, this can make a significant difference in performance. If a procedure of this type is invoked from multiple places, you can make it into an include file and include it each place where it would otherwise be run. In this way, the code remains reusable but it is compiled directly in place wherever it is used. This can make the code much faster.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095